package com.click.app.model;

import com.click.app.Functions;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * @author Joel Chuca Condo
 * @date 07/04/2009
 */
@Entity
@Table(name = "laundry_items")
public class LaundryItem extends BaseObject {

    private Long id;
    private Integer quantity;
    private Integer failQuantity;
    private PantDesign pantDesign;
    private LaundryRequestItem laundryRequestItem;
    private Double unitPrice;
    private Double unitTotalPrice;
    private Double totalPrice;
    private Double failUnitPrice;
    private Double failTotalPrice;
    
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "id_laundry_item")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY )
    @JoinColumn(name = "id_laundry_request_item", nullable = false)
    public LaundryRequestItem getLaundryRequestItem() {
        return laundryRequestItem;
    }

    public void setLaundryRequestItem(LaundryRequestItem laundryRequestItem) {
        this.laundryRequestItem = laundryRequestItem;
    }
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "id_pant_design", nullable = false)
    public PantDesign getPantDesign() {
        return pantDesign;
    }

    public void setPantDesign(PantDesign pantDesign) {
        this.pantDesign = pantDesign;
    }

    @Column(name = "quantity")
    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    @Column(name = "fail_quantity")
    public Integer getFailQuantity() {
        return failQuantity;
    }

    public void setFailQuantity(Integer failQuantity) {
        this.failQuantity = failQuantity;
    }

    @Column(name = "unit_total_price")
    public Double getUnitTotalPrice() {
        return unitTotalPrice;
    }

    public void setUnitTotalPrice(Double unitTotalPrice) {
        this.unitTotalPrice = unitTotalPrice;
    }

   
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    } 
    

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof LaundryItem)) {
            return false;
        }
        LaundryItem other = (LaundryItem) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.click.app.model.LaundryItem[id=" + id + ", quantity="+quantity+", failQuantity="+failQuantity+", size="+pantDesign.getModelSize().getValueSize()+"]";
    }

    @Column(name = "fail_total_price")
    public Double getFailTotalPrice() {
        return Functions.getDouble3Decimal(failTotalPrice);
    }

    public void setFailTotalPrice(Double failTotalPrice) {
        this.failTotalPrice = Functions.getDouble3Decimal(failTotalPrice);
    }

    @Column(name = "fail_unit_price")
    public Double getFailUnitPrice() {
        return Functions.getDouble3Decimal(failUnitPrice);
    }

    public void setFailUnitPrice(Double failUnitPrice) {
        this.failUnitPrice = Functions.getDouble3Decimal(failUnitPrice);
    }

    @Column(name = "total_price")
    public Double getTotalPrice() {
        return Functions.getDouble3Decimal(totalPrice);
    }

    public void setTotalPrice(Double totalPrice) {
        this.totalPrice = Functions.getDouble3Decimal(totalPrice);
    }

    @Column(name = "unit_price")
    public Double getUnitPrice() {
        return Functions.getDouble3Decimal(unitPrice);
    }

    public void setUnitPrice(Double unitPrice) {
        this.unitPrice = Functions.getDouble3Decimal(unitPrice);
    }

}
